<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div{
        border:1px solid #ccc ;
        margin:10px;
        padding:10px;

      }
    </style>
  </head>
  <body>
    
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    

    <script src="../d3.js"></script>
    <script>
      // const array = ['apple','orange','banana','mango','lemon'];
      
      // const selection = d3.select('body').selectAll('div')
      //   .data(array)
      //   .text(d=>d)
      //   .enter()
      //   .append('div')
      //   .text(d=>d)
      
      const array = ['apple','orange','banana'];

      const selection = d3.select('body')
          .selectAll('div')
          .data(array,(d,i)=>d?i+1:i)
          .text(function(d){return this.innerHTML+" . " + d})
          .exit()
          .remove()

    </script>
  </body>
</html>
